/**
 * Definition for singly-linked list.
 * function ListNode(val) {
 *     this.val = val;
 *     this.next = null;
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */

var reverseList = function (head) {
    // 创建dummy结点
    let dummy = new ListNode()
    // 使其指向head
    dummy.next = head
    // 三剑客
    let pre = null
    let cur = head
    let next = head
    while (cur) {
        next = cur.next
        // 指向翻转
        cur.next = pre
        // 三剑客向后移动
        pre = cur
        cur = next
    }
    // 指向最后一个结点
    dummy.next = pre
    return dummy.next
};